package com.yty.demo._7_thread;

import static java.lang.Thread.sleep;

/**
 * @author: yangtaoyao
 * @time: 2020/1/14 10:10
 * @description: 死锁
 */
public class DeadLockTest {
    private static int anInt1=10;
    private static int anInt2=20;

    public static void main(String[] args) {

        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
               synchronized (DeadLockTest.class){
                   System.out.println("线程["+Thread.currentThread().getName()+"]已获得DeadLockTest.class类锁，请求获取Test.class类锁");
                   for (int i = 0; i < 5; i++) {
                       synchronized (Test.class){
                           System.out.println("线程["+Thread.currentThread().getName()+"]已获得Test.class类锁--"+i);
                       }
                   }
               }
            }
        });
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (Test.class){
                    System.out.println("线程["+Thread.currentThread().getName()+"]已获得Test.class类锁，请求获取DeadLockTest.class类锁");
                    for (int i = 0; i < 5; i++) {
                        synchronized (DeadLockTest.class){
                            System.out.println("线程["+Thread.currentThread().getName()+"]已获得Test.class类锁，请求DeadLockTest.class类锁");
                        }
                    }
                }
            }
        });

        t1.start();
        t2.start();
    }
}
class Test{

}